<?php
//Set up the system
require('config.include.php');
//Auth stuff
require('auth.include.php');
//Rebuild if requested
$rebuilt=false;
if(isset($_GET['rebuild'])) {
	//Set paths
	$blockCodePath='../'.THEMEFOLDER.'/'.THEME.'/'.THEME.'.bcd';
	$themehtml='../'.THEMEFOLDER.'/'.THEME.'/'.THEME.'.html';
	//Start timer
	$buildTmr=new timer();
	//New template
	$bcGen=new ubertemplate;
	//Add html
	$bcGen->addCode(file_get_contents($themehtml));
	//Get the blockcode
	$blockCode=$bcGen->getBlockCode();
	//Write to file
	$blockCodeFile=fopen($blockCodePath,'w+');
	fwrite($blockCodeFile,$blockCode);
	//Get time
	$buildtime=$buildTmr->getElapsed();
	$rebuilt=true;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Rebuild Template</title>
<link rel="stylesheet" href="admin.css" />
</head>

<body>
<div id="wrapper">
	<div id="header">
    	<?php echo('<a href="../" class="breadcrumb">'.SITE_TITLE.'</a> &raquo; <a href="dashboard.php" class="breadcrumb">Dashboard</a> &raquo; <a href="rebuildtemplate.php" class="breadcrumb">Rebuild Template</a>'); ?>
    </div>
    <div id="sidebar">
<?php
	require('nav.include.php');
?>
    </div>
    <div id="content">
        <div class="contentblock">
        <?php
			if($rebuilt)
				echo('<h2>Template rebuilt</h2>
				Processing: '.round($buildtime,3).' seconds.<br />
				<h2>BlockCode</h2>
				<form action="#">
				<textarea cols="60" rows="30" class="full">'.htmlentities($blockCode,ENT_QUOTES,"UTF-8").'</textarea>
				</form>');
			else
				echo('
    	<h2>Rebuild Template</h2>
				Changes to your template html are not visible to Pure until you rebuild the blockcode file.<br />
				This is required to cut down on processing time.');
			
			echo('
			<br />
			<a href="rebuildtemplate.php?rebuild">Click to rebuild</a>
			<br />
			or, <a href="settemplate.php">edit template HTML</a>');
		?>
		</div>
    </div>
    <div id="footer">
    </div>
</div>
</body>
</html>